1. Field of the Invention
The present invention relates generally to multi-tasking systems and, more particularly, to a technique for detecting corruption associated with a stack in a storage device.
2. Background of the Present Invention
A real time embedded system often provides a multi-tasking environment in order to meet diverse application requirements. In a multi-tasking environment, an individual stack (i.e., an individual work space) is typically required for each task. Each stack provides a location, or a group of locations, where dynamic function variables may be stored as needed for a corresponding task. Typically, each stack is allocated a dedicated range of sequential memory, although a stack can also be allocated a dedicated space of non-sequential memory. Regardless, stacks have always had problems in the areas of overflow and underflow.
Stack overflow occurs when the stack memory is insufficient to meet workload demand. Stack underflow occurs when a task attempts to pop too many function variables off of the stack. The net result of either operation is the corruption of adjacent memory. Corruption of adjacent memory results in non-predictable behavior and difficult to impossible casual analysis of the problem (i.e., finding the source of the problem).
Traditional solutions to stack overflow and underflow problems are to either significantly over-allocate stack memory or use hardware write protect schemes. The first solution basically ignores the problem, hoping but not ensuring that it never happens. Since stack corruption is a dynamic condition, this solution is fraught with shortcomings. The second solution solves the detection problem, but at the cost of additional hardware complexity and corresponding hardware failure rates.
A software solution to the above-described stack overflow and underflow problems is to keep track of the number of function variables that are on the stack by adding one (i.e., +1) to a counter whenever a push operation occurs, and by subtracting one (i.e., −1) from the counter whenever a pop operation occurs. However, whenever a complex push/pop operation is performed (i.e., when push/pop operations are performed in a number of different places), it is difficult to ensure that all such places perform the requisite addition/subtraction operation. As an alternative, a centralized procedure and/or function for performing the push and pop operations can be created, wherein the appropriate addition and subtraction operations are performed therein. However, this requires calling such procedures and/or functions, which requires additional memory space and processor time.
In view of the foregoing, it would be desirable to provide a technique for overcoming the above-described stack overflow and underflow problems, while also overcoming the shortcomings of the above-described prior art solutions. More particularly, it would be desirable to provide a technique for detecting stack corruption in a multi-tasking environment.